package com.wuzhiming.istudy.controller;

import com.alibaba.fastjson.JSONObject;
import com.wuzhiming.istudy.pojo.Comment;
import com.wuzhiming.istudy.utils.LogUtils;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @ClassName: CommentController
 * @Description: 评论课程控制器
 * @Author:zhimingw
 * @Version 1.0
 * @since 2022/3/16 20:01
 */
@RestController
public class CommentController extends BaseController{
    private Logger logger = LogUtils.getInstance(CommentController.class);

    @PostMapping("/addComment")
    public String addComment(Comment comment){
        comment.setUserId(userInfo.getId());
        comment.setTime(new Date());
        if(commentService.addComment(comment)){
            result.setCode(200);
            System.out.println("添加评论成功");
        }else{
            result.setCode(500);
            System.out.println("添加评论失败");
        }
        return JSONObject.toJSONString(result);
    }

    /**
     * @Description: 修改评论状态
     * @Param: [id]
     * @return: java.lang.String
     * @Author: zhimingw
     * @Date: 2021/7/20
     */
    @GetMapping("/changeCommentStatus")
    public String changeCommentStatus(@RequestParam("id") Integer id,@RequestParam("status") Integer status){
        Comment comment = new Comment();
        comment.setId(id);
        comment.setStatus(status);
        if (commentService.update(comment)) {
            result.setCode(200);
            logger.warn("【成功】修改评论状态");
        }else {
            result.setCode(500);
            logger.warn("【失败】修改评论状态");
        }
        return JSONObject.toJSONString(result);
    }
}
